import { Navigate, useLocation } from "react-router-dom"
import { useMatchRouter } from "../../utils"
import { router_items } from ".."
function AuthRouter(props:{children:JSX.Element}){
    const {pathname} = useLocation()
    const token = localStorage.getItem("token")
    const router_item =useMatchRouter(pathname,router_items)
    if(router_item?.meta.unWantedAuth||token)
        return props.children
    return <Navigate to={"/login"}/>

}
export default AuthRouter